<template>
	<view class="container" :style="'height:'+ screenHeight +'px !important;'">
		<view class="scan_box">
			<view class="scan_title"> <text>{{scan_title}} </text> <view style="height: 15rpx;"> </view><text>{{scan_desc}}</text></view>
			<view class="scan_btn" @click="scan_code">
				<image src="/static/image/scan.png" mode="aspectFit"></image>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				screenHeight: 0,
				scan_title: '请扫描《朝读经典 · 德育学本》',
				scan_desc: '书后二维码'
			}
		},
		onLoad(options) {
			this.screenHeight = uni.getSystemInfoSync().windowHeight;
		},
		methods: {
			scan_code() {
				let that = this;
				uni.scanCode({
					onlyFromCamera: true,
					success(res) {
						let path = res.path;
						getApp().globalData.bbcode = that.getParam(path, "bbcode");
						getApp().globalData.njcode = that.getParam(path, "njcode");
						getApp().globalData.xdcode = that.getParam(path, "xdcode");
						getApp().globalData.xkcode = that.getParam(path, "xkcode");
						getApp().globalData.njname = that.getParam(path, "njname");
						uni.switchTab({
							url: '/pages/chapters/chapters'
						})
					},
					fail() {
						uni.showToast({
							icon: "none",
							title: "扫码失败，请重新再试!"
						})
					}
				})
			},
			getParam(path, name) {
				var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
				if (reg.test(path))
					return unescape(RegExp.$2.replace(/\+/g, " "));
				return "";
			}
		}
	}
</script>


<style lang="scss" scoped>
	@import "./scan.scss";
</style>
